package cc.vv.btpartyjob.partymanager.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import cc.vv.baselibrary.view.LKCircleImageView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.moudel.bean.TeamMemberBean
import cc.vv.lkbasecomponent.util.LKScreenUtil
import cc.vv.lkimagecomponent2.LKImage
import cc.vv.lkimagecomponent2.lib.mode.ScaleMode
import java.util.*

/**
 * 社区大党委中网格数据展示，最多4个网格数据
 * Created by  Chen.qi on 2018/10/24.
 */
class TeamMemberView : LinearLayout {
    /**
     * 上下文
     */
    private var mContext: Context? = null
    /**
     * 父布局
     */
    private var llSelectedAll: LinearLayout? = null

    constructor(context: Context) : this(context, null) {
        mContext = context
    }

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) {
        mContext = context
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        mContext = context
        val inflateView = View.inflate(context, R.layout.layout_operation_view, null)
        llSelectedAll = inflateView.findViewById(R.id.ll_lov_showAll)
        this.addView(inflateView)
    }


    /**
     * 填充选项数据
     *
     * @param optionList 数据集
     */
    fun addAllSelectedFileView(optionList: ArrayList<TeamMemberBean>?) {
        if (null == optionList) {
            return
        }
        //清除
        clearAllJobOptionView()
        val picHeight = LKScreenUtil.dp2px(42f)
        val layoutParams1 = LayoutParams(LayoutParams.MATCH_PARENT, LKScreenUtil.dp2px(70f))
        for (i in 0 until optionList.size) {
            val view = LayoutInflater.from(mContext).inflate(R.layout.layout_loudong_team_member, null)
            view.layoutParams = layoutParams1
            val memberPic = view.findViewById<LKCircleImageView>(R.id.iv_lLtm_memberPic)
            val memberName = view.findViewById<TextView>(R.id.iv_lLtm_memberName)
            val memberTel = view.findViewById<TextView>(R.id.iv_lLtm_memberTelPhone)
//            val layoutParams = memberPic.layoutParams as RelativeLayout.LayoutParams
//            layoutParams.width = picHeight
//            layoutParams.height = picHeight
//            memberPic.layoutParams = layoutParams
            val jobOptionObj = optionList[i]
            LKImage.load().load(jobOptionObj?.memberUrl).scale(ScaleMode.CENTER_CROP)
                    .rectRoundCorner(3)
                    .placeHolder(R.mipmap.icon_def_image)
                    .error(R.mipmap.icon_def_image).into(memberPic)
            memberName.text = jobOptionObj?.memberName
            memberTel.text = jobOptionObj?.memberTel
            llSelectedAll?.addView(view)
        }
    }

    /**
     * 清除view
     */

    private fun clearAllJobOptionView() {
        llSelectedAll?.removeAllViews()
    }


}